/*
 * @# GalleryServiceImpl.java 2011-12-23 下午04:22:02
 * 
 * Copyright (C) 2010 - 2011 广州羿安信息科技有限公司
 * Guangzhou ianswer information technology co. ltd.
 * 
 * All rights reserved!
 */
package com.ianswer.px.album.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.ianswer.common.orm.PublicDao;
import com.ianswer.px.album.entity.Gallery;
import com.ianswer.px.album.service.GalleryService;

/**
 * 画廊处理逻辑.
 * 
 * @author alvin hwang
 */
@Service("galleryService")
public class GalleryServiceImpl implements GalleryService {

	@Resource(name = "publicDao")
	private PublicDao publicDao;
	
	@Override
	public List<Gallery> queryShowGalleries(Long userId) {
		Gallery gallery = new Gallery();
		gallery.showType().setUserId(userId);
		return publicDao.query("galleries.query", userId);
	}

	@Override
	public List<Gallery> queryDressGalleries(Long userId) {
		Gallery gallery = new Gallery();
		gallery.dressType().setUserId(userId);
		return publicDao.query("galleries.query", userId);
	}

	@Override
	public Long insert(Gallery gallery) {
		return (Long) publicDao.insert("galleries.insert", gallery);
	}

	@Transactional
	@Override
	public void delete(Long userId, Long galleryId) {
		Gallery gallery = new Gallery();
		gallery.setId(galleryId);
		gallery.setUserId(userId);
		publicDao.delete("galleries.delete", gallery);
		publicDao.delete("galleries.deleteAlbums", gallery);
	}

	@Override
	public void incrAlbums(Long userId, Long galleryId) {
		Gallery gallery = new Gallery();
		gallery.setId(galleryId);
		gallery.setUserId(userId);
		publicDao.update("galleries.incrAlbums", gallery);
	}

	@Override
	public void decrAlbums(Long userId, Long galleryId) {
		Gallery gallery = new Gallery();
		gallery.setId(galleryId);
		gallery.setUserId(userId);
		publicDao.update("galleries.decrAlbums", gallery);
	}

	@Override
	public void update(Long userId, Long galleryId, String name) {
		Gallery gallery = new Gallery();
		gallery.setId(galleryId);
		gallery.setUserId(userId);
		gallery.setName(name);
		publicDao.update("galleries.updateName", gallery);
	}

}
